package com.turnengine.client.local.player.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Set Player Action Queue Limit Data Serializer.
 */
public class SetPlayerActionQueueLimitDataSerializer extends AbstractCommandDataSerializer<Integer> implements ISetPlayerActionQueueLimitDataSerializer {

	/**
	 * Creates a new Set Player Action Queue Limit Data Serializer.
	 */
	public SetPlayerActionQueueLimitDataSerializer() {
		super(SetPlayerActionQueueLimit.COMMAND_ID);
	}

	@Override
	public Integer readReturnValue(IDataReader reader) throws IOException {
		Integer value = reader.readIntegerObject(true);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, Integer value) throws IOException {
		writer.writeIntegerObject(value, true);
	}

	@Override
	public IExecutableCommand<Integer> readRequest(IDataReader reader) throws IOException {

		// Read fields
		long loginId = reader.readLong();
		int instanceId = reader.readInt();
		int limit = reader.readInt();

		// Create object
		SetPlayerActionQueueLimit object = new SetPlayerActionQueueLimit();
		object.setLoginId(loginId);
		object.setInstanceId(instanceId);
		object.setLimit(limit);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<Integer> argument) throws IOException {
		SetPlayerActionQueueLimit object = (SetPlayerActionQueueLimit) argument;

		// Get fields
		long loginId = object.getLoginId();
		int instanceId = object.getInstanceId();
		int limit = object.getLimit();

		// Write fields
		writer.writeLong(loginId);
		writer.writeInt(instanceId);
		writer.writeInt(limit);
	}

	@Override
	public IExecutableCommandResponse<Integer> newResponse() {
		return new SetPlayerActionQueueLimitResponse();
	}
}
